/*
 * @Description:设备管理
 * @Author: 刘相卿
 * @Company: 山东方亚信息技术有限公司
 * @Date: 2020-10-17 13:38:36
 * @LastEditTime: 2020-10-21 15:24:01
 * @LastEditors: 刘相卿
 */

const Mock = require('mockjs')

let getOverview = (data) => {
  return Mock.mock({
    data: {
      overview: {
        deviceTotal: 200, // 设备总数
        undeployDeviceCount: 22, // 未部署设备数
        abnormalTotal: 52, // 非正常设备总数
        warningDeviceCount: 10, // 预警
        faultDeviceCount: 2, // 故障
        offlineDeviceCount: 20, // 离线
        notActiveDeviceCount: 20, // 未激活
      },
      list: [
        {
          type: '电气火灾',
          total: 50,
          normalCount: 2,
          count: [
            {
              name: '预警',
              count: 2,
            },
            {
              name: '故障',
              count: 2,
            },
            {
              name: '失联',
              count: 2,
            },
            {
              name: '未激活',
              count: 1,
            },
          ],
        },
        {
          type: '烟感',
          total: 50,
          normalCount: 2,
          count: [
            {
              name: '预警',
              count: 2,
            },
            {
              name: '故障',
              count: 2,
            },
            {
              name: '失联',
              count: 2,
            },
            {
              name: '未激活',
              count: 1,
            },
          ],
        },
        {
          type: '消防水',
          total: 50,
          normalCount: 2,
          count: [
            {
              name: '预警',
              count: 2,
            },
            {
              name: '故障',
              count: 2,
            },
            {
              name: '失联',
              count: 2,
            },
            {
              name: '未激活',
              count: 1,
            },
          ],
        },
        {
          type: '气体',
          total: 50,
          normalCount: 2,
          count: [
            {
              name: '预警',
              count: 2,
            },
            {
              name: '故障',
              count: 2,
            },
            {
              name: '失联',
              count: 2,
            },
            {
              name: '未激活',
              count: 1,
            },
          ],
        },
        {
          type: 'AI视频',
          total: 50,
          normalCount: 2,
          count: [
            {
              name: '预警',
              count: 2,
            },
            {
              name: '故障',
              count: 2,
            },
            {
              name: '失联',
              count: 2,
            },
            {
              name: '未激活',
              count: 1,
            },
          ],
        },
      ],
    },
  })
}

let getDeviceInfoById = () => {
  return Mock.mock({
    data: {
      deviceNo: 111100000, // 设备编号
      deviceStatus: 1, // 设备状态
      deviceEQ: 90, // 设备电量
      deviceSignal: 1, // 网络信号
      deviceType: 1, // 设备类型
      deployPlace: '济南市高新区铭盛大厦', // 部署位置
      placeId: 34, // 部署位置ID
    },
  })
}

let getList = () => {
  return Mock.mock({
    'data|20': [
      {
        'deviceNo|8': /[a-z][A-Z][0-9]/, // 设备编号
        deviceStatus: 1, // 设备状态
        deviceSignal: 1, // 网络信号
        deviceType: 1, // 设备类型
        deployPlace: '济南市高新区铭盛大厦', // 部署位置
        placeId: 34, // 部署位置ID
        updateTime: '2020-10-17 10:12:13',
      },
    ],
  })
}

module.exports = {
  [`GET /device/getOverview`](ctx) {
    const { data } = getOverview(ctx.request.body)
    ctx.body = {
      code: 200,
      msg: '操作成功',
      data: data,
    }
  },
  [`GET /device/getList`](ctx) {
    const { data } = getList(ctx.request.body)
    ctx.body = {
      code: 200,
      msg: '操作成功',
      data: {
        list: data,
        total: data.length,
        pageSize: 10,
        pageNo: 1,
      },
    }
  },
  [`GET /device/getInfoById`](ctx) {
    const { data } = getDeviceInfoById(ctx.request.body)
    ctx.body = {
      code: 200,
      msg: '操作成功',
      data: data,
    }
  },
}
